﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;
using WebGrease.Css.Extensions;

using CanDoo;
using CanDoo.Core;
using CanDoo.Data;
using CanDoo.Web;
using CanDoo.FineUI;
using CanDoo.Extensions;
using CanDoo.Oil.Core.Models;
using CanDoo.Oil.Core.Contracts;
using CanDoo.Admin.Core.Contracts;
using CanDoo.Core.Data;
using FineUIPro;

namespace CanDoo.Oil.WebApp.storeOilSerialNum
{
    public partial class Default : ListPageBase<IOilSerialNumContract, OilSerialNum>
    {


        public IInStoreTypeContract InStoreTypeContract { get; set; }
        public IOutStoreTypeContract OutStoreTypeContract { get; set; }
        public IWarehouseContract WarehouseContract { get; set; }
        public IProductContract ProductContract { get; set; }
        public ICustomerContract CustomerContract { get; set; }
        public IOilSalesSerialNumContract OilSalesSerialNumContract { get; set; }

        #region 方法
        protected override void InitGrid()
        {
            Selector = p => new
            {
                p.InStoreType,
                p.InStoreTypeId,
                p.InStoreId,
                p.OutStoreType,
                p.OutStoreTypeId,
                p.OutStoreId,
                p.Warehouse,
                p.WarehouseId,
                p.Product,
                p.ProductId,
                p.SerialNumber,
                p.ServiceCenter,
                p.ServiceCenterId,
                p.Customer,
                p.CustomerId,
                p.OilSalesSerialNum,
                p.OilSalesSerialNumId,
                p.OilPort,
                p.UpTime,
                p.LastOil,
                p.DownTime,
                p.BirthDay,
                p.Batch,
                p.OverdueDay,
                p.Id,
                p.Name,
                p.SellBackName,
                p.OutName,
                p.BuyBackName,
                p.Status
            };
            base.InitGrid();
        }

        protected override void Search()
        {
            var key = SearchKey.GetValue();
            var instoretypeId = SearchInStoreType.GetValue().ToLong();
            var outstoretypeId = SearchOutStoreType.GetValue().ToLong();
            var warehouseId = SearchWarehouse.GetValue().ToLong();
            var productId = SearchProduct.GetValue().ToLong();
            var customerId = SearchCustomer.GetValue().ToLong();
            var oilsalesserialnumId = SearchOilSalesSerialNum.GetValue().ToLong();
            if(string.IsNullOrEmpty(key) == false)
            {
                Filter = Filter.And(p => p.Name.Contains(key));
            }
            if (instoretypeId >  0L)
                Filter = Filter.And(p => p.InStoreTypeId == instoretypeId);
            if (outstoretypeId >  0L)
                Filter = Filter.And(p => p.OutStoreTypeId == outstoretypeId);
            if (warehouseId >  0L)
                Filter = Filter.And(p => p.WarehouseId == warehouseId);
            if (productId >  0L)
                Filter = Filter.And(p => p.ProductId == productId);
            if (customerId >  0L)
                Filter = Filter.And(p => p.CustomerId == customerId);
            if (oilsalesserialnumId >  0L)
                Filter = Filter.And(p => p.OilSalesSerialNumId == oilsalesserialnumId);



        }
        #endregion

        #region 事件
        #region Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //FineUIListHelper.BindDDL<InStoreType>("入库方式", InStoreTypeContract.GetResolvedTree(), 0L, SearchInStoreType);
                FineUIListHelper.BindDDL(InStoreTypeContract.EntityName, this.InStoreTypeContract.GetSelectList(), 0L, SearchInStoreType);
                //FineUIListHelper.BindDDL<OutStoreType>("出库方式", OutStoreTypeContract.GetResolvedTree(), 0L, SearchOutStoreType);
                FineUIListHelper.BindDDL(OutStoreTypeContract.EntityName, this.OutStoreTypeContract.GetSelectList(), 0L, SearchOutStoreType);
                //FineUIListHelper.BindDDL<Warehouse>("仓库", WarehouseContract.GetResolvedTree(), 0L, SearchWarehouse);
                FineUIListHelper.BindDDL(WarehouseContract.EntityName, this.WarehouseContract.GetSelectList(), 0L, SearchWarehouse);
                //FineUIListHelper.BindDDL<Product>("产品", ProductContract.GetResolvedTree(), 0L, SearchProduct);
                FineUIListHelper.BindDDL(ProductContract.EntityName, this.ProductContract.GetSelectList(), 0L, SearchProduct);
                //FineUIListHelper.BindDDL<Customer>("服务中心客户", CustomerContract.GetResolvedTree(), 0L, SearchCustomer);
                FineUIListHelper.BindDDL(CustomerContract.EntityName, this.CustomerContract.GetSelectList(), 0L, SearchCustomer);
                //FineUIListHelper.BindDDL<Customer>("终端客户", CustomerContract.GetResolvedTree(), 0L, SearchCustomer);
                FineUIListHelper.BindDDL(CustomerContract.EntityName, this.CustomerContract.GetSelectList(), 0L, SearchCustomer);
                //FineUIListHelper.BindDDL<OilSalesSerialNum>("售油机", OilSalesSerialNumContract.GetResolvedTree(), 0L, SearchOilSalesSerialNum);
                FineUIListHelper.BindDDL(OilSalesSerialNumContract.EntityName, this.OilSalesSerialNumContract.GetSelectList(), 0L, SearchOilSalesSerialNum);
                InitGrid();
            }
        }
        #endregion

        #endregion 事件

    }
}
